home *** CD-ROM | disk | FTP | other *** search
/ Commodore Free 14 / Commodore_Free_Issue_14_2007_Commodore_Computer_Club.d64 / t.dtv mod < prev    next >
Text File  |  2023-02-26  |  8KB  |  288 lines

  1. u
  2. DTV mod: C64 DTV in a C64 case
  3. http://joco.homeserver.hu/
  4.  
  5. When I first heard about the C64DTV, I
  6. knew this is what I had been waiting
  7. for. I always wanted a clone compatible
  8. with the original C64, but more power-
  9. ful with extra resources like other
  10. resolutions, more memory, etc.
  11. Fortunately the C64DTV (I own a
  12. European PAL version V2) can be hacked:
  13.  
  14.  http://galaxy22.dyndns.org/dtv/v2
  15.   /index.html
  16.  
  17. Many ways, & you can find a lot of info
  18. about it on the Internet. See my
  19. referencesbelow!
  20.  
  21. I checked many hacking pages, so I knew
  22. that it is possible to attach an
  23. original disk drive via the IEC bus, &
  24. it is possible to attach a PS2 keyboard
  25. to the unit. But as far as I know, no
  26. one tried to put the DTV back in an
  27. original C64 box (I can be wrong
  28. though). Then I found Lars
  29. Pontoppidan's MMC2IEC available here at
  30.  
  31.  http://pontoppidan.info/lars
  32.   /index.php?proj=mmc2iec
  33.  
  34. A project which uses MMC/SD card for
  35. storage & it acts like a 1541 drive
  36. (sure a little bit better).
  37.  
  38. As I am experienced with micro-
  39. controllers as well as C/C++ &
  40. assembly language, I knew that there is
  41. a way to handle the original C64
  42. keyboard matrix with a microcontroller.
  43.  
  44. Unfortunately the DTV does not have the
  45. keyboard rows/cols pinouts, so there
  46. is no perfect solution, but the PS2
  47. implementation might be good enough for
  48. my purposes.
  49.  
  50. I thought, the same microcontroller -in
  51. this case it's the Atmel ATMEGA32 with
  52. 32 I/O pins - could scan the keyboard
  53. matrix & send necessary press & release
  54. codes on the PS2 bus to the DTV.
  55.  
  56. The PS2 port on the DTV is
  57. unidirectional; it means the host never
  58. sends data to the keyboard. Great.
  59. Thanks to the other researches that
  60. cool guys have done before, I had
  61. enough knowledge about everything. I
  62. knew how to generate PS2 codes, I knew
  63. how to scan the keyboard matrix, &
  64. thanks to Lars Pontoppidan, I had a
  65. solution for the IEC interface. All I
  66. had to do is just modify the original
  67. MMC2IEC design a little bit, &
  68. implement the keyboard scanner
  69. function.
  70.  
  71. I spent about 3 weekends with this.
  72. Unfortunately the PS2 interface for the
  73. DTV has some odds. It also has some
  74. remapping, therefore my implementation
  75. had to do some workaround for special
  76. keys. For example on the C64 keyboard
  77. the key 2 has the " sign when it's
  78. shifted, the PC keyboard has the sign
  79. @. There are some other mismatches,
  80. which made life difficult. Anyway, what
  81. you see here is the first version. I
  82. know it's not perfect, but it works.
  83.  
  84. I do not want to write about the other
  85. obvious hacks for the DTV, you can find
  86. out yourselves (like joy port, video
  87. fix, updating the flash, etc), just
  88. Google them. I am not really concerned
  89. about the IEC & MMC stuff either, Lars
  90. did a great job. I am only writing
  91. about the keyboard matrix here.
  92.  
  93. Theory: the IEC bus has higher priority
  94. than the keyboard matrix. Whenever the
  95. IEC works which means when you LOAD or
  96. SAVE something -there is no keyboard
  97. scanning. When there is no disk
  98. handling, the microcontroller has an
  99. idle time, in this case I scan the
  100. keyboard matrix as fast as I can. Every
  101. time I compare the last scanned values
  102. with the new ones, so in case of one
  103. key there are 4 different states
  104. (0-pressed, 1-released) if we have bit
  105. #1 as the old bit, & bit #0 is the new
  106. bit: 00: was pressed before & still
  107. pressed 01: was pressed, now it's
  108. released 10: was released, now it's
  109. pressed 11: was released, still
  110. released 
  111.  
  112. In case of 00 & 11 there is nothing to
  113. do, because the state of given key has
  114. not changed. If we get the 01 value, we
  115. have to generate a release code,
  116. whereas if we get the 10 value, we have
  117. to generate the press code.
  118.  
  119. Because of the different keys (like 2/@
  120. - 2/" or 6/^ - 6/&) sometimes it's more
  121. complicated, so we need to change the
  122. code or virtually press or release the
  123. shifts. This is all done by the
  124. UpdateKeyMatrix() function.
  125.  
  126. Let me highlight some points about the
  127. schematic. First of all, it's pretty
  128. simple. I used a 40PIN version of the
  129. microcontroller, where we have PORTA &
  130. PORTC on the "right side" of the chip.
  131. This makes the soldering very easy.
  132. I use the PORTA & PORTC for keyboard
  133. matrix (COLS & ROWS), but in this
  134. version I do not handle the RESTORE
  135. button. (maybe in the next version)
  136. I do not use LEDs, but they are on the
  137. PORTD bit #0 & bit #1. They were in the
  138. original MMC2IEC project but I just
  139. don't need them.
  140.  
  141. Between the DTV & the AtMEGA micro-
  142. controller there are five data lines:
  143. PS2Data, PS2Clock, IECData, IECClock,
  144. IECAtn. These are on the PORTD.
  145.  
  146. The PORTB is used to handle the SPI
  147. bus, this is what communicates with the
  148. SD/MMC card.
  149.  
  150. I use the internal 8MHz clock source,
  151. but it's just around 7.6MHz because of
  152. the 3.3V Vcc voltage.
  153.  
  154. Some points about the software: The
  155. main loop in the mmc2iec.c is pretty
  156. simple. It scans the keyboard if there
  157. is nothing else to do, otherwise the
  158. IEC handler works. Obviously I
  159. initialized the keyboard handler with
  160. the InitKeyMatrix() function before I
  161. use the UpdateKeyMatrix().
  162.  
  163. While (TRUE) {SHIFT-+}
  164. // scan the keyboard normally (IDLE
  165.  time)
  166.  
  167. UpdateKeyMatrix()
  168. ;// IEC-MMC handler (LOAD/SAVE)
  169.  
  170. Interface_handler()
  171. ; {SHIFT--}
  172. Ps2.c: this is the one that sends a
  173. byte on the PS2 bus to the DTV.
  174. Simple as hell, as the PS2 port is only
  175. output for the microcontroller. I am
  176. not even sure that the parity bit
  177. generation is correct. If not, that
  178. means the DTV does not care about the
  179. parity bit. Good.
  180.  
  181. C64keymtx.c: the keyboard handler
  182. module. There is an array called "r"
  183. (unsigned char r[64] PROGMEM) which
  184. contains the PS2 codes. The only one
  185. exception is the colon ":" key, which
  186. is handled differently & I used 0xff
  187. for this key. Obviously, the table
  188. contains the keys based on the
  189. schematic - as you can see, the rows &
  190. cols are mixed, but it was the easiest
  191. way to solder & I did not mind changing
  192. the bits in the software. It doesnt
  193. matter anyway.
  194.  
  195. How it works? Read the source. It tells
  196. everything.
  197.  
  198. One more thing to mention. You will
  199. find out that I used the GOTO statement
  200. inside the UpdateKeyMatrix() to break
  201. up the loops some cases. I know that
  202. every book says you should never use
  203. GOTOs. Bull. I use what I want to use.
  204. And besides, this is a microcontroller
  205. application where speed & space are
  206. factors. I tried some different ways.
  207. Anything else generates more code. BTW
  208. the WINAVR is just perfect, the best
  209. compiler I've ever seen. Still, some
  210. bytes matter to me. So for those who
  211. are against the GOTO: try to write an
  212. assembly code without braches & jumps.
  213. Good luck for that. Gotos don't mix up
  214. your code. If they do for you, you
  215. should find another job to do.
  216. Selling postcards for example. :-)
  217.  
  218. Downloads:
  219.  
  220. The shematics of the project:
  221.  http://joco.homeserver.hu
  222.   /mmc2iecKB/img/sch.gif
  223. Source code:
  224.  http://joco.homeserver.hu
  225.   /mmc2iec KB/source.zip
  226.  
  227. mixed with the original MMC2IEC code.
  228. You need WINAVR to compile
  229.  
  230. Links & references:
  231.  
  232. Lars Pontoppidan's page, MMC2IEC
  233.  http://pontoppidan.info/lars
  234.   /index.php?proj=mmc2iec
  235. DTV hacking:
  236.  http://galaxy22.dyndns.org/dtv
  237.   /v2/index.html
  238. Daniel Kahlin's webpage:
  239.  http://www.kahlin.net/daniel
  240.   /dtv/
  241.  
  242. PonyProg, the application I use to
  243. program the Atmel microcontroller:
  244.  http://www.lancos.com/prog.html
  245.  
  246. A lo cost programmer for Atmel ATMEGA32
  247.  http://gopchandani.wordpress.com
  248.   /2007/01/18/the-atmega32programmer/
  249.  
  250. (Don't forget to turn off the JTAG
  251. interface of the ATMEGA32, otherwise
  252. the PORTC won't work.)
  253.  
  254. Things to do for the next release (just
  255. some ideas in my mind)
  256.  
  257. Accurate RESTORE key handling. Well,
  258. there is no RESTORE handler at all now. 
  259. LED's. Just to make it perfect.
  260. Modify the DTV's flash so I won't need
  261. to press the CTRL key always.
  262. Absoultely required. Video fix &
  263. dedicated video & audio ports on the
  264. box. Won't be too hard.
  265. Soldering the joy ports as well. I will
  266. do.
  267. Hack the original IEC routines to speed
  268. up the load & save. There must be a way
  269. as we can modify the FLASH.
  270.  
  271.  Thanks, Mr. Kahlin
  272.  
  273. Addendum:
  274.  
  275. -Here you can see the fusebits settings
  276. for the microcontroller: Fusebits
  277. Diagram Shown above -You can download
  278. the compiled version in intel-hex
  279. format: mmc2iec.hex
  280.  
  281.  http://joco.homeserver.hu/mmc2iecKB
  282.   /mmc2iec.hex
  283.  (right-click, then Save target as)
  284.  
  285. Jozsef
  286.   http://joco.homeserver.hu/
  287.  
  288.